package com.stylefeng.guns.rest.modular.App.service.impl;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.model.CommonKeyValue;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.Tools.Result;
import com.stylefeng.guns.rest.modular.App.dao.OrderCustomerCodeMapper;
import com.stylefeng.guns.rest.modular.App.model.OrderCustomerCode;
import com.stylefeng.guns.rest.modular.App.service.IOrderCustomerCodeService;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.toolkit.IdWorker;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;

/**

 * 乘客评分 Service 实现 
 * @author sasazaixian
 * @Date 2018-12-25 10:45
 */
@Service
public class OrderCustomerCodeServiceImpl extends ServiceImpl<OrderCustomerCodeMapper,OrderCustomerCode> implements IOrderCustomerCodeService {

    @Resource
    private OrderCustomerCodeMapper orderCustomerCodeMapper;

    /**
     * 删除乘客评分
     * @param orderCustomerCode
     * @return     
     */
    @Transactional
    public int deleteOrderCustomerCode(OrderCustomerCode orderCustomerCode, String token)throws Exception{
        if(orderCustomerCode==null ){
            throw new RuntimeException("参数不全！");
        }
        return this.orderCustomerCodeMapper.deleteOrderCustomerCode(orderCustomerCode);
    }
    /**
     * 批量删除乘客评分
     * @param ids 主键ID数组
     * @return 
     */
    @Transactional
    public int deleteBatchOrderCustomerCode(String[] ids,String token)throws Exception{
        return this.orderCustomerCodeMapper.deleteBatchOrderCustomerCode(ids);
    }
    /**
     * 查询乘客评分列表
     * @param orderCustomerCode 乘客评分对象
     * @return
     */
    public List<OrderCustomerCode> selectListOrderCustomerCode(OrderCustomerCode orderCustomerCode,String token)throws Exception{
        return  this.orderCustomerCodeMapper.selectListOrderCustomerCode(orderCustomerCode);
    }
    /**
	 * 分页查询乘客评分列表
     * @param pager 分页对象
     * @return
     */     
    public  Map pageListOrderCustomerCode(Pager pager,String token) throws Exception{
        Page page=new Page(pager.getPageNumber(),pager.getPageSize());
        page.setRecords(orderCustomerCodeMapper.selectListOrderCustomerCode(page,(OrderCustomerCode)pager.getObj()));
        List<OrderCustomerCode> list = page.getRecords();
        Map mapDate = new HashMap();
        mapDate.put("rows", list);
        mapDate.put("total", page.getTotal());
        mapDate.put("page", page.getCurrent());
        mapDate.put("pageCount", page.getPages());
        return mapDate;
    }
    /**
     * 同一个事务 互斥锁查询
     * @param orderCustomerCode 乘客评分对象
     * @return 
     */
    @Transactional
    public  List<OrderCustomerCode> selectListOrderCustomerCodeForUpdate(OrderCustomerCode orderCustomerCode)throws Exception{
        return  this.orderCustomerCodeMapper.selectListOrderCustomerCodeForUpdate(orderCustomerCode);
    }
    /**
     * 通过主键id查询的乘客评分列表
     * @param id 主键id
     * @return     
     */
    public  OrderCustomerCode findOrderCustomerCodeById(String id,String token)throws Exception{
        return  this.orderCustomerCodeMapper.findOrderCustomerCodeById(id);
    }

    /**
     * 新增乘客评分数据
     * @param orderCustomerCode  乘客评分对象
     * @return
     */
    @Transactional
    public int insertOrderCustomerCode(OrderCustomerCode orderCustomerCode,String token) throws Exception {
        if(orderCustomerCode==null || orderCustomerCode.getOccCode()==null ){
           throw new RuntimeException("参数不全！");
        }
        OrderCustomerCode selOrderCustomerCode=new OrderCustomerCode();
        selOrderCustomerCode.setOiId(orderCustomerCode.getOiId());
        List<OrderCustomerCode> list=this.selectListOrderCustomerCodeForUpdate(selOrderCustomerCode);
        if(list!=null && list.size()>0){
            throw new RuntimeException("请勿重复评分！");
        }
        orderCustomerCode.setCreateTime(new Date());
        return this.orderCustomerCodeMapper.insertOrderCustomerCode(orderCustomerCode);
    }
    
    /**
     * 更新乘客评分数据
     * @param orderCustomerCode 乘客评分对象
     * @return
     */
    @Transactional
    public int updateOrderCustomerCode(OrderCustomerCode orderCustomerCode,String token) throws Exception {
        return  this.orderCustomerCodeMapper.updateOrderCustomerCode(orderCustomerCode);
    }

}
